<!doctype html>
<!--
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
Code distributed by Google as part of the polymer project is also
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
-->
<html>
  <head>
    <title>bindProperties</title>
    <script src="../../../webcomponentsjs/webcomponents.js"></script>
    <link rel="import" href="../../polymer.html">
    <script src="../../../tools/test/htmltest.js"></script>
    <script src="../../../tools/test/chai/chai.js"></script>
  </head>
  <body>

    <polymer-element name="x-baz" attributes="val" noscript>
      <template>{{ val }}</template>
    </polymer-element>

    <polymer-element name="x-bar" attributes="val" noscript>
      <template>
        <x-baz id=baz val="{{ val }}"></x-baz>
      </template>
    </polymer-element>

    <polymer-element name="x-bat" attributes="val" noscript>
      <template>{{ val }}</template>
    </polymer-element>

    <polymer-element name="x-foo" attributes="val" noscript>
      <template>
        <x-bar id=bar val="{{ val }}"></x-bar>
        <x-bat id=bat val="{{ val }}"></x-bat>
      </template>
    </polymer-element>

    <polymer-element name="bind-properties-test">
      <template>
        <x-foo id="foo" val="{{ obj.path.to.value }}"></x-foo>
      </template>
      <script>
        Polymer('bind-properties-test', {
          myVal: null,
          ready: function() {
            this.obj = {
              path: { to: { value: 3 }}
            };
            this.test();
          },
          test: function() {
            var foo = this.$.foo;
            var bar = this.$.foo.$.bar;
            var bat = this.$.foo.$.bat;
            var baz = this.$.foo.$.bar.$.baz;

            chai.assert.equal(foo.val, 3);
            chai.assert.equal(bar.val, 3);
            chai.assert.equal(bat.val, 3);
            chai.assert.equal(baz.val, 3);

            foo.val = 4;

            chai.assert.equal(foo.val, 4);
            chai.assert.equal(bar.val, 4);
            chai.assert.equal(bat.val, 4);
            chai.assert.equal(baz.val, 4);

            baz.val = 5;

            chai.assert.equal(foo.val, 5);
            chai.assert.equal(bar.val, 5);
            chai.assert.equal(bat.val, 5);
            chai.assert.equal(baz.val, 5);

            this.obj.path.to.value = 6;

            chai.assert.equal(foo.val, 6);
            chai.assert.equal(bar.val, 6);
            chai.assert.equal(bat.val, 6);
            chai.assert.equal(baz.val, 6);

            done();
          }
        });
      </script>
    </polymer-element>
    <bind-properties-test></bind-properties-test>
  </body>
</html>
